#version 330 core


layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aCol;
layout (location = 2) in vec2 aTexCoord;

out vec3 oCol;
out vec3 oPos;
out vec2 oTexCoord;

uniform float uW;
uniform float uH;
uniform mat4 uModel;

// 注意：一定是先计算出当前的姿态，在做fix，否则fix之后做姿态， 物体又会应为屏幕的宽高比导致拉伸或者收缩
vec4 fix(vec3 aPos) {
    vec4 pos = uModel * vec4(aPos, 1.0);

    float r = uW / uH;

    if (uW < uH) {
        pos.x *= r;
    } else {
        pos.y *= r;
    }

    return pos;
}

void main() {
    gl_Position = fix(aPos);
    oCol = aCol;
    oTexCoord = aTexCoord;
}
